package com.malie.myspringboot.rabbitmq.springbootRabbitmq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Test1 {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/t")
    public String test() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            String message = "早睡早起身体好" + i;
            Thread.sleep(1000 * 1);
            rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_FANOUT_HUANG, RabbitmqConfig.QUEUE_1, message);
            System.out.println(" [x] Sent '" + message + "'");

        }
        return "";
    }

    // 直接型 每发十条消息到队列中写一次表
    @RequestMapping("/update")
    public String update() throws InterruptedException {
        for (int i = 0; i < 50; i++) {
            String message = "第" + i + "条消息";
            Thread.sleep(1000 * 1);
            rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_FANOUT_HUANG, "", message);
            System.out.println(" [x] Sent '" + message + "'");

        }
        return "";
    }
}
